const cityurl = "https://geoapi.qweather.com/v2/city/lookup?key=5d34d140932e49f2941ce656ff36c9eb&location="
const weatherurl = "https://devapi.qweather.com/v7/weather/now?key=5d34d140932e49f2941ce656ff36c9eb&location="
const futureurl = "https://devapi.qweather.com/v7/weather/3d?key=5d34d140932e49f2941ce656ff36c9eb&location="
Page({
  data: {
    city: "",
    temperature: "",
    wind: "",
    cityid: "",
    daily: []
  },
  input(e) {
    console.log(e)
    let city = e.detail.value
    this.setData({
      city: city
    })
  },
  search() {
    let url = cityurl + this.data.city
    console.log("cityidurl:",url)
    let that = this
    wx.request({
      url,
      success(e) {
        console.log("cityid:",e)
        let cityid = e.data.location[1].id
        that.setData({
          cityid
        })
        let wurl = weatherurl + cityid
        console.log("weatherurl:",wurl)
        wx.request({
          url: wurl,
          success(e) {
            console.log("weather:",e)
            let temperature = e.data.now.temp
            let wind = e.data.now.windDir
            let textDay = e.data.now.text
            let humidity = e.data.now.humidity
            let windSpeed = e.data.now.windSpeed
            let pressure = e.data.now.pressure
            that.setData({
              temperature,
              wind,
              textDay,
              humidity,
              windSpeed,
              pressure
            })
          }
        })
        let furl = futureurl + cityid
          console.log("futureurl:",furl)
        wx.request({
          url: furl,
          success(e) {
            console.log("future:",e)
            let daily = e.data.daily
            that.setData({
              daily
            })
          }
        })
      }
    })
  }
})